package com.example.day02;

import android.content.Context;
import android.content.Entity;
import android.content.pm.LabeledIntent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;


import java.util.ArrayList;

public class Recy_Adapter extends RecyclerView.Adapter {
    Context context;
    ArrayList<Bean> resultsBeans;

    public Recy_Adapter(Context context, ArrayList<Bean> resultsBeans) {
        this.context = context;
        this.resultsBeans = resultsBeans;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        if (viewType == 1) {
            View inflate = LayoutInflater.from(context).inflate(R.layout.activity_name, parent, false);
            return new ViewHolder1(inflate);
        }else {
            View inflate = LayoutInflater.from(context).inflate(R.layout.activity_name2, parent, false);
            return new ViewHolder2(inflate);
        }
    }
    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        int viewType = getItemViewType(position);
        if(viewType==1){
            ViewHolder1 viewHolder1= (ViewHolder1) holder;
            viewHolder1.t1.setText(resultsBeans.get(position).getStep());
            viewHolder1.t2.setText(resultsBeans.get(position).getName());
        }else {
            ViewHolder2 viewHolder2= (ViewHolder2) holder;
            viewHolder2.t3.setText(resultsBeans.get(position).getName()+"");
            viewHolder2.t4.setText(resultsBeans.get(position).getStep()+"");

        }


    }

    @Override
    public int getItemCount() {
        return resultsBeans.size();
    }
    public class ViewHolder1 extends RecyclerView.ViewHolder{
            TextView t1;
            TextView t2;
            public ViewHolder1(@NonNull View itemView) {
                super(itemView);
                t1=itemView.findViewById(R.id.text1);
                t2=itemView.findViewById(R.id.text2);

            }
    }
    public class ViewHolder2 extends RecyclerView.ViewHolder{

        TextView t4;
        TextView t3;
        public ViewHolder2(@NonNull View itemView) {
            super(itemView);

            t3=itemView.findViewById(R.id.text3);
            t3=itemView.findViewById(R.id.text4);
        }
    }

    @Override
    public int getItemViewType(int position) {
        if(position%2==0){
            return 1;
        }else {
            return 2;
        }

    }
}
